package com.mhjy.input.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mhjy.input.service.INhMbMemberService;
import com.mhjy.input.repository.entity.NhMbMemberEntity;
import com.mhjy.input.repository.mapper.NhMbMemberMapper;
import com.mhjy.input.repository.model.BaseResultModel;
import com.mhjy.input.units.UnitHelper;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Random;


@Service
public class NhMbMemberService extends ServiceImpl<NhMbMemberMapper, NhMbMemberEntity> implements INhMbMemberService {
    @Override
    public BaseResultModel selectAll() {
        QueryWrapper wrapper = new QueryWrapper();
        List<NhMbMemberEntity> list = baseMapper.selectList(wrapper);
        if (list != null && list.size() <= 0)
            return new BaseResultModel(98, "查询数据为空");
        else
            return new BaseResultModel(0, "", list);
    }

    @Override
    public BaseResultModel add(NhMbMemberEntity entity) {
        entity.setDcId(baseMapper.selectDcId());
        //entity.setDcId(Long.valueOf(new Random().nextInt()));
        entity.setId(1000000L + entity.getDcId());
        entity.setBatchNo(UnitHelper.GetBatchNo());
        entity.setLastUpdatedTime(new Date());
        entity.setLastUpdatedBy("admin");
        Integer k = baseMapper.insert(entity);
        return k > 0 ? new BaseResultModel(0, "成功") : new BaseResultModel(99, "失败");
    }
}
